package com.example.yiwu;

import android.content.Intent;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.widget.ImageButton;
import android.widget.LinearLayout;

public class MainActivity extends FragmentActivity implements View.OnClickListener {

    private LinearLayout mTabHomepage;
    private LinearLayout mTabPublish;
    private LinearLayout mTabMe;

    private ImageButton mHomepageImg;
    private ImageButton mMeImg;

    private android.support.v4.app.Fragment homepageFragment;
    private android.support.v4.app.Fragment meFragment;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.activity_main);
        initView();
        initEvent();
        // initFragment(0);
    }

    private void initView() {
        mTabHomepage = (LinearLayout) findViewById(R.id.id_tab_homepage);
        mTabPublish = (LinearLayout) findViewById(R.id.id_tab_publish);
        mTabMe = (LinearLayout) findViewById(R.id.id_tab_me);
        mHomepageImg = (ImageButton) findViewById(R.id.id_tab_homepage_img);
        mMeImg = (ImageButton) findViewById(R.id.id_tab_me_img);
    }

    private void initEvent() {
        mTabHomepage.setOnClickListener(this);
        mTabPublish.setOnClickListener(this);
        mTabMe.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        if (v.getId() != R.id.id_tab_publish) restartButton();
        switch (v.getId()) {
            case R.id.id_tab_homepage:
                //initFragment(0);
                break;
            case R.id.id_tab_me:
                //initFragment(1);
                break;
            case R.id.id_tab_publish:
//                Intent intent = new Intent(MainActivity.this,PublishActivity.class);
//                startActivity(intent);
        }
    }

    private void restartButton() {
        mHomepageImg.setImageResource(R.drawable.explore);
        mMeImg.setImageResource(R.drawable.me);
    }
}
/*
    private void initFragment (int index){
        FragmentManager fragmentManager = getSupportFragmentManager();
        FragmentTransaction transaction = fragmentManager.beginTransaction();
        hideFragment(transaction);
        if(homepageFragment == null || meFragment == null){
            if(homepageFragment == null) {
                homepageFragment = new HomeFragment();
                transaction.add(R.id.fl_content, homepageFragment);
            }
            else {
                meFragment = new MeFragment();
                transaction.add(R.id.fl_content,meFragment);
            }
        }
        switch (index){
            case 0:
                transaction.show(homepageFragment);
                break;
            case 1:
                transaction.show(meFragment);
                break;
        }
        transaction.commit();
        switch (index){
            case 0:
                mHomepageImg.setImageResource(R.drawable.explore_chosen);
                break;
            case 1:
                mMeImg.setImageResource(R.drawable.me_chosen);
                break;
        }
    }
*/
    /*
    private void hideFragment(FragmentTransaction transaction){
        if(homepageFragment != null){
            transaction.hide(homepageFragment);
        }
        if(meFragment != null){
            transaction.hide(meFragment);
        }
    }
}
*/